#define _CRT_SECURE_NO_WARNINGS 1

// 1
/*
#include <iostream>
#include <string>
#include <set>
using namespace std;
int main()
{
	string ori, del;
	getline(cin, ori);
	getline(cin, del);
	set<char> dels(del.begin(), del.end());
	for (int i = 0; i < ori.size(); i++)
		if (dels.count(ori[i]))
			ori.erase(ori.begin() + i--);
	cout << ori << endl;
	return 0;
}
*/

// 3
#include <iostream>
#include <string>
#include <vector>
using namespace std;
using ll = long long;
//ll n, s, h, y, ans;
ll n, s, ans;
int main()
{
	int n; cin >> n;
	//string ori; cin >> ori;
	//ll hpos = 0;
	vector<ll> hs;
	for (ll i = 0; i < n; i++) {
		char ch; cin >> ch;
		switch (ch) {
		case 's':s++; break;

		case 'h':hs.emplace_back(s); 
			if(hs.size() >= 2) hs[hs.size() - 1] += hs[hs.size() - 2];
				s=0; break;
		case 'y':
			for(ll x : hs)
				ans += x; break;

		}
	}
	cout << ans << endl;
	return 0;
}